/**
 * @description: 处理#嵌套数组类型的tokens
 * @param {*} tokens
 * @return {*}nestedTokens
 */
export default function nestTokens(tokens) {
  let nestedTokens = []
  let sections = []
  // debugger
  for (let i = 0; i < tokens.length; i++) {
    let token = tokens[i]
    if (token[0] === "#") {
      token[2] = []
      sections.push(token)
    } else if (token[0] === "/") {
      let pop_section = sections.pop()
      if (sections.length !== 0) {
        sections[sections.length - 1][2].push(pop_section)
      } else {
        nestedTokens.push(pop_section)
      }
    } else {
      if (sections.length === 0) {
        nestedTokens.push(token)
      } else {
        sections[sections.length - 1][2].push(token)
      }
    }
  }
  return nestedTokens
}
